package cn.amsser.myshowcase.arithmetic.search;

public class BinarySearch {

	public int search(int[] array, int target) {

		int start = 0;
		int end = array.length;

		int index = (start + end) / 2;

		while (start < end) {
			if (array[index] > target) {
				end = index - 1;
			} else if (array[index] < target) {
				start = index + 1;
			} else {
				return index;
			}
		}

		return -1;

	}

}
